% Date: Wed, 7 Mar 90 17:04:23 EST
% From: Denys Duchier <duchier-denys@YALE.ARPA>
% Subject: Escapable Verbatim Environment
% Keywords: LaTeX, environment, font changes
% 
% I wrote the example environment a long time ago to do verbatim-like
% output with font changes. Last week, I added the comment environment
% (available only inside example) to allow the insertion of comments,
% processed like normal text and possibly offset from the left margin,
% in an example listing.
% 
% Perhaps others will find this useful too.
% 
% --Denys
% 
%-----File: example.sty----------------------------------------------
% 
% Copyright Denys Duchier, Yale University, 1988.
%
% \begin{example}...\end{example} $@$O(Jverbatim$@$K$h$/;w$?4D6-$@$,!"(J
% \($@5U%9%i%C%7%e(J)$@$H(J{ }$@$ODL>o$N(JTeX$@$N%=!<%9%U%!%$%k$HF1Ey$N07$$$K$J$k!#(J
% $@$3$l$K$h$C$F!"%U%)%s%H$NJQ99$J$I(Jverbatim$@4D6-$G$O$G$-$J$$$3$H$,2DG=$K$J$k!#(J
%
% \begin{example*}{OFFSET}...\end{example*} $@$O!"(JOFFSET$@$NCM$@$1%F%-%9%H$r(J
% $@%$%s%G%s%H$9$k$3$H$r=|$1$P(J\begin{example}...\end{example}$@$HF1$8$G$"$k!#(J
%
% $@$^$?!"(Jexample$@4D6-$N$J$+$G$O(J\begin{comment}...\end{comment}$@$rMxMQ$7$F(J
% $@DL>o$N(JTeX$@%F%-%9%H$r=PNO$G$-$k!#(J\begin{comment}[OFFSET] $@$G$O!"(JOFFSET$@$V$s(J
% $@%3%a%s%H!&%F%-%9%H$r%$%s%G%s%H$9$k!#(J

\newdimen\exampleleftmargin \exampleleftmargin\z@
\def\examplesavespecials{\let\xmpl@space\ \let\xmpl@dollar\$
\let\xmpl@amper\&\let\xmpl@hash\#\let\xmpl@caret\^\let\xmpl@cntlK\^^K
\let\xmpl@underscore\_\let\xmpl@cntlA\^^A\let\xmpl@percent\%
\let\xmpl@tilde\~}
\def\examplerestorespecials{\let\ \xmpl@space\let\$\xmpl@dollar
\let\&\xmpl@amper\let\#\xmpl@hash\let\^\xmpl@caret\let\^^K\xmpl@cntlK
\let\_\xmpl@underscore\let\^^A\xmpl@cntlA\let\%\xmpl@percent
\let\~\xmpl@tilde}
\def\exampledospecials{\do\ \do\$\do\&\do\#\do\^\do\^^K\do\_\do\^^A\do\%\do\~}
\def\example@verbatim{\let\comment\xmpl@comment\let\endcomment\xmpl@@endcomment
  \list{}{\parsep\parskip
  \leftmargin\exampleleftmargin
  \labelwidth\z@
  \itemindent\z@
  \def\makelabel##1{##1}}\item[]\if@minipage\else\vskip\parskip\fi
  \leftskip\@totalleftmargin
  \rightskip\z@
  \parindent\z@
  \parfillskip\@flushglue
  \parskip\z@
  \@tempswafalse
  \def\par{\if@tempswa\hbox{}\fi\@tempswatrue\@@par}\obeylines\tt
  \examplesavespecials
  \let\do\@makeother\dospecials}
\def\@example{\let\dospecials\exampledospecials
  \example@verbatim\frenchspacing\@vobeyspaces}
\def\example{\exampleleftmargin\z@\@example}
\let\endexample\endlist
\@namedef{example*}#1{\exampleleftmargin#1\@example}
\expandafter\let\csname endexample*\endcsname\endexample
%
\def\xmpl@comment{\@ifnextchar [{\xmpl@@comment}{\xmpl@@comment[0pt]}}
\def\xmpl@@comment[#1]{\begingroup
  \examplerestorespecials
  \catcode`\ =10 \catcode`\^^M=5
  \list{}{\leftmargin\exampleleftmargin
  \advance\leftmargin #1}\item[]\rm\ignorespaces}
\def\xmpl@@endcomment{\endlist\endgroup\vskip-\baselineskip}
